import json

from fastapi import APIRouter, Request
from re_common.baselibrary.utils.core.requests_core import MsgCode

from apps.core.m_route import ContextIncludedRoute
from apps.core.return_info import ReturnInfo, SUCCESS
from apps.crawler_platform.core_platform.core_g import RedisKey

router = APIRouter(route_class=ContextIncludedRoute)


@router.post("/showinfo/tasks")
async def save_task(request: Request):
    return_info = ReturnInfo()
    redis = request.app.state.redis
    dicts = {}
    async for name, val in redis.hscan_iter(RedisKey.taskinfo):
        dicts[name] = json.loads(val)
    return_info.status = SUCCESS
    return_info.msg_code = MsgCode.SUCCESS_CODE
    return_info.msg = "获取redis taskinfo 成功"
    return_info.data = dicts
    return return_info


